<include file="public:header"/>
<include file="public:sidebar"/>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            代理管理
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">代理</li>
        </ol>
    </section>
    <hr>
    <!-- Main content -->
    <section class="content">
        <div class="col-md-12">
            <div class="tools">
                <div class="tools-button">
                    <!--<a href="{:Url('mch/add')}" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">-->
                    <!--<i class="layui-icon">&#xe654;</i>添加-->
                    <!--</a>-->
                    <!--<a class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger deleteAll">-->
                    <!--<i class="layui-icon">&#xe640;</i>删除-->
                    <!--</a>-->
                </div>
                <div class="tool-search" style="margin-top: 10px;">
                    <form class="layui-form" autocomplete="off">
                        <div class="layui-inline">
                            <input type="text" name="nickname" placeholder="请输入昵称"
                                   class="layui-input">
                            <input type="hidden" name="page" id="pages" value="">
                        </div>
                        <div class="layui-inline">
                            <input type="text" name="open_id" placeholder="请输入OpenId"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline">
                            <input type="text"  placeholder="请选择时间"
                                   readonly name="date" style="width: 200px"
                                   class="layui-input" id="test1">
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                        </div>
                    </form>
                </div>
            </div>
            <table class="table layui-table">
                <thead>
                <tr>
                    <td>会员名</td>
                    <th>OpenId</th>
                    <th>头像</th>
                    <th>地址</th>
                    <th>加入时间</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                <volist name="list" id="vo">
                    <tr>
                        <td>{$vo.nickname}</td>
                        <td>{$vo.open_id}</td>
                        <td>
                            <img src="{$vo.avatar}" width="50" alt="{$vo.nickname}">
                        </td>
                        <td>{$vo.address}</td>
                        <td>{$vo.create_time}</td>
                        <td>
                            <a href="javascript:;" onclick="del('{$vo.id}')">删除</a>
                        </td>
                    </tr>
                </volist>
                </tbody>
            </table>
            <div class="pull-right" id="page"></div>
        </div>
    </section>
</div>
<include file="public:footer"/>
<script id="demo" type="text/html">
    {{#  layui.each(d.data, function(index, item){ }}
    <tr>
        <td>{{item.nickname}}</td>
        <td>{{item.open_id}}</td>
        <td>
            <img src="{{ item.avatar }}" width="50" alt="{{item.nickname}}">
        </td>
        <td>{{item.address}}</td>
        <td>{{item.create_time}}</td>
        <td>
            <a href="javascript:;" onclick="del('{{item.id}}')">删除</a>
        </td>
    </tr>
    {{#  }); }}
</script>
<script>
    var currentPage = 1;
    var url = "{:Url('member/index')}";
    var ids = [];
    $(document).ready( function () {
        layui.use(['layer','form','laydate','laypage'],function () {
            var layer = layui.layer,
                laydate = layui.laydate,
                form = layui.form,
                laypage = layui.laypage;

            form.on('submit(search)',function (data) {
                init();
                return false;
            });
            laydate.render({
                elem: '#test1',
                type: 'date',
                range: '~',
                format: 'yyyy-MM-dd',
            });
            laypage.render({
                elem: 'page',
                count: Number('{$total}'),
                limit: 10,
                layout: ['prev','page','next','skip'],
                theme: '#c00',
                jump: function(obj, first){
                    $('#pages').val(obj.curr);
                    if(!first){
                        init();
                    }
                }
            });
        });
    });
    function init(){
        var data = $('form').serialize();
        layui.use(['laytpl','layer'],function () {
            var laytpl = layui.laytpl,
                layer = layui.layer;
            var index = layer.load(2,{shade: [0.8, '#000']});
            $.post(url,data,function (result) {
                layer.close(index);
                if(result.code === 0){
                    var getTpl = demo.innerHTML;
                    laytpl(getTpl).render(result.data, function(html){
                        $('table>tbody').html(html);
                        $('#pages').val(result.data.current_page);
                    });
                }
            });
        });
    }
    function del(id) {
        layer.confirm('您确定要删除吗，删除后不能恢复?', {icon: 3, title:'提示'}, function(index){
            $.post('{:Url("member/del")}',{id: id},function (result) {
                if(result.code ){
                    layer.alert(result.msg,{icon: 5});
                    return false;
                }
                layer.alert(result.msg,{icon: 6,end:function () {
                        init();
                    }});
            });
            layer.close(index);
        });
    }
</script>